﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Devices.DeviceSaleView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:Interactions="http://schemas.microsoft.com/expression/2010/interactions"
                     xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
                     xmlns:be="clr-namespace:Corina.Interactivity.Silverlight;assembly=Corina.Interactivity.Silverlight"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="销售情况"
                     d:DesignHeight="480"
                     d:DesignWidth="800"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:DeviceSaleViewmodel />
    </navigation:PageView.DataContext>

    <navigation:PageView.Resources>
        <Style x:Key="style_pager" TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid>
                            <Grid Background="{StaticResource HighlightBrush}" Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource TemplatedParent}}" />
                            <TextBlock Margin="5,3" Text="{Binding }" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </navigation:PageView.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <sdk:AutoCompleteBox ItemsSource="{Binding DeviceKindCollection}"
                                     MinimumPrefixLength="0"
                                     SelectedItem="{Binding SelectedDeviceKind,
                                                            Mode=TwoWay}"
                                     ValueMemberPath="Name"
                                     be:AutoCompleteBoxHelper.OtherPaths="Name,Description">
                    <sdk:AutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" />
                        </DataTemplate>
                    </sdk:AutoCompleteBox.ItemTemplate>
                    <i:Interaction.Triggers>
                        <be:AutoCompleteBoxTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:AutoCompleteBoxTrigger>
                    </i:Interaction.Triggers>
                </sdk:AutoCompleteBox>
                <TextBlock Grid.Column="1"
                           Margin="12,0,0,0"
                           VerticalAlignment="Center"
                           Text="设备序列号：" />
                <TextBox Grid.Column="2"
                         Width="200"
                         HorizontalAlignment="Left"
                         Text="{Binding DeviceSn,
                                        Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}">
                    <i:Interaction.Triggers>
                        <be:TextBoxEnterKeyTrigger>
                            <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                        </be:TextBoxEnterKeyTrigger>
                    </i:Interaction.Triggers>
                </TextBox>

                <Button Grid.Column="3"
                        Width="60"
                        Margin="24,0,0,0"
                        Command="{Binding InsertCommand}"
                        Content="新增" />

            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12"
                              AutoGenerateColumns="False"
                              CanUserSortColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding ItemsCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Width="60"
                                                Binding="{Binding ItemIndex}"
                                                Header="序号" />
                        <sdk:DataGridTemplateColumn Header="设备">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock VerticalAlignment="Center">
                                        <Run Text="{Binding DeviceSn}" />
                                        <Run Text="【" />
                                        <Run Text="{Binding Kind}" />
                                        <Run Text="】" />
                                    </TextBlock>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTextColumn Binding="{Binding UserName}" Header="用户" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding Salesperson}"
                                                Header="销售员" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding ManufactureDate}"
                                                Header="生产日期" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding TransferKind}"
                                                Header="数据传输模块" />
                        <sdk:DataGridTextColumn Width="120"
                                                Binding="{Binding SaleDate}"
                                                Header="时间" />
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

            <StackPanel Grid.Row="2"
                        HorizontalAlignment="Right"
                        Orientation="Horizontal">
                <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
                <Button Margin="12,0"
                        Command="{Binding PreviousPageCommand}"
                        Style="{StaticResource PreviousPageButtonStyle}" />
                <TextBlock Margin="12,0" VerticalAlignment="Center">
                    <Run Text="{Binding Index}" />
                    <Run Text="/" />
                    <Run Text="{Binding PagesCount}" />
                </TextBlock>
                <Button Margin="12,0"
                        Command="{Binding NextPageCommand}"
                        Style="{StaticResource NextPageButtonStyle}" />
                <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
            </StackPanel>
        </Grid>
        <controls:PromptDialog Title="{Binding Operation,
                                               ConverterParameter=ENTITYOPERATION,
                                               Converter={StaticResource EnumTranslationConverter}}"
                               CloseCommand="{Binding CancelCommand}"
                               Padding="50"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="450"
                               WindowWidth="720">
            <Grid Margin="12">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="12" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ListBox Grid.Column="0"
                             ItemContainerStyle="{StaticResource style_pager}"
                             ItemsSource="{Binding UserPager}"
                             SelectedItem="{Binding SelectedUserPage,
                                                    Mode=TwoWay}" />

                    <ListBox Grid.Column="1"
                             AllowDrop="True"
                             FontFamily="Portable User Interface"
                             ItemContainerStyle="{StaticResource UserItemStyle}"
                             ItemsSource="{Binding UserCollection}"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled">

                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                        <Interactivity:Interaction.Triggers>
                            <Interactivity:EventTrigger EventName="SelectionChanged">
                                <Interactions:CallMethodAction MethodName="UserSelectionChanged" TargetObject="{Binding}" />
                            </Interactivity:EventTrigger>
                        </Interactivity:Interaction.Triggers>
                    </ListBox>

                    <ListBox Grid.Column="3"
                             AllowDrop="True"
                             ItemContainerStyle="{StaticResource UnsaledDeviceItemStyle}"
                             ItemsSource="{Binding UnsaledDeviceCollection}"
                             ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel />
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>

                    </ListBox>

                    <ListBox Grid.Column="4"
                             ItemContainerStyle="{StaticResource style_pager}"
                             ItemsSource="{Binding DevicePager}"
                             SelectedItem="{Binding SelectedDevicePage,
                                                    Mode=TwoWay}" />
                </Grid>

                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid HorizontalAlignment="Left" AllowDrop="True">
                        <Path Width="48"
                              Height="48"
                              Margin="0,0,0,0"
                              AllowDrop="True"
                              Data="{Binding Source={StaticResource ICON_SHOPCAR},
                                             Converter={StaticResource StringToPathGeometryConverter}}"
                              Fill="{StaticResource HighlightBrush}"
                              RenderTransformOrigin="0.5,0.5"
                              Stretch="Uniform">
                            <Path.RenderTransform>
                                <TransformGroup>
                                    <TransformGroup.Children>
                                        <RotateTransform Angle="0" />
                                        <ScaleTransform ScaleX="1" ScaleY="1" />
                                    </TransformGroup.Children>
                                </TransformGroup>
                            </Path.RenderTransform>

                        </Path>
                        <Grid HorizontalAlignment="Right" VerticalAlignment="Bottom">
                            <Ellipse Width="18"
                                     Height="18"
                                     HorizontalAlignment="Center"
                                     VerticalAlignment="Center"
                                     Fill="#88000000"
                                     Opacity=".75" />
                            <TextBlock HorizontalAlignment="Center"
                                       VerticalAlignment="Center"
                                       Text="{Binding Entities.Count}" />
                        </Grid>

                        <Interactivity:Interaction.Triggers>
                            <Interactivity:EventTrigger EventName="MouseLeftButtonUp">
                                <Interactions:CallMethodAction MethodName="OnDrop" TargetObject="{Binding}" />
                            </Interactivity:EventTrigger>
                            <Interactivity:EventTrigger EventName="MouseEnter">
                                <Interactions:CallMethodAction MethodName="OnMouseEnter" TargetObject="{Binding}" />
                            </Interactivity:EventTrigger>
                        </Interactivity:Interaction.Triggers>
                    </Grid>

                    <StackPanel Grid.Column="1"
                                VerticalAlignment="Center"
                                Orientation="Horizontal"
                                Visibility="{Binding ShowPriceInout,
                                                     Converter={StaticResource BooleanToVisibilityConverter}}">
                        <TextBlock Margin="12,0,0,0"
                                   VerticalAlignment="Center"
                                   Text="输入价格：" />
                        <TextBox Width="200" Text="{Binding SalePrice, Mode=TwoWay}">
                            <i:Interaction.Triggers>
                                <be:TextBoxEnterKeyTrigger>
                                    <be:ExecuteCommandAction Command="{Binding SubmitPriceCommand}" />
                                </be:TextBoxEnterKeyTrigger>
                            </i:Interaction.Triggers>
                        </TextBox>
                    </StackPanel>

                    <StackPanel Grid.Column="2"
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Orientation="Horizontal">
                        <Button Width="60"
                                Margin="12,0"
                                Command="{Binding SubmitCommand}"
                                Content="提交" />
                        <Button Width="60"
                                Command="{Binding CancelCommand}"
                                Content="取消" />
                    </StackPanel>
                </Grid>
            </Grid>
        </controls:PromptDialog>
    </Grid>
</navigation:PageView>
